package com.sunrise.controller.user;

import com.sunrise.pojo.system.User;
import com.sunrise.service.UserService;
import com.sunrise.vo.system.user.UserVO;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import result.GraceJSONResult;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Author: liansen
 * @Date: 2024-02-03  17:25
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/createOrUpdate")
    public GraceJSONResult createOrUpdate(@Valid @RequestBody UserVO userVO) {
        User user = new User();
        BeanUtils.copyProperties(userVO, user);
        if (userVO.getId() == null){
            userService.save(user);
        }else {
            userService.updateById(user);
        }
        return GraceJSONResult.ok();
    }
}
